Módulo:Sandbox/ShipInfoKai
local BaseData = require('Module:BaseData') local Ship = require('Module:Ship') local ShipCardKai = require('Module:ShipCardKai') local ResourceIcons = require('Module:ResourceIcons') local StatIcons = require('Module:StatIcons') local Formatting = require('Module:Formatting') local format = require('Module:StringInterpolation').format local ShipInfoKai = BaseData{ _catbomb = "Catbomb.png|300px", _unbuildable = "Unbuildable", _remodel_level = "Remodel Level", _build_time = "Build Time", _default_slot_num = 4, _normal_construction = "Normal", _normal_construction_category = ":Category:Ships buildable in Normal Construction", _large_ship_construction = "LSC", _large_ship_construction_category = ":Category:Ships buildable in Large Ship Construction", _ship_data_documentation = "Template:ShipDataDocumentation/EditIntro", _edit_link_text = "Edit", _localized_name_template = " ${localized_name}", _kekkon_max_template = "Maximum after marriage: ${value}", _nick_template = " (${nick} ${japanese_nick})", _overridden_category_template = "Category:Pages that override data modules", _fields = { "edit_link", "rarity", "bg_color", "name", "localized_name", "id", "japanese_name", "nick", "class", "type", "image", "hp", "firepower", "armor", "torpedo", "evasion", "aa", "aircraft", "asw", "speed", "los", "range", "luck", "consumption", "modernization", "scrap", "build_remodel_header", "build_remodel_info", "slots", "slot_details", "gun_fit_properties", "improvement", }, _slot_template = [[|- align=center style="background-color: whitesmoke; line-height: 1.1;" | style="width: 36px; height: 36px; background-color: ${color};${extra_style}" | ${icon} | colspan="4" style="width: 190px;" | ${equipment} | style="width: 50px;" | ${slot_size} ]], _template = , _remodel_cost_template = [[ Remodel Cost ${remodel_cost} ]], _reversion_cost_template = [[ Reversion to ${suffix} ${level_items} ${resources} ]], _gun_fit_properties_template = format{ ${subtitle} ${gun_fit_groups}, subtitle = Formatting:tooltip("Large Caliber Fit Gun Properties", "Based on experimental findings")}, _gun_fit_group_template = ${fit_group} ${fit} , _improvement_template = [[ Improvement ${category_tree} ]], _improvement_category_template = "Equipment that can be improved with ${ship_name} as helper ship", } function ShipInfoKai:Infobox(args) return self{ _args = args, }:create_infobox() end function ShipInfoKai:edit_link() self._vars.edit_link = Formatting:format_edit_link(self._ship_data_module, self._edit_link_text, self._ship_data_documentation) end function ShipInfoKai:bg_color() local back = self._ship:back() self._vars.top_bg_color, self._vars.top_extra_style = Formatting:format_ship_back(back), Formatting:extra_style_background_image(back and back > 7, back and back > 6, self._ship:overlay()) or "" end function ShipInfoKai:rarity() self._vars.rarity = Formatting:format_ship_rarity(self._ship:rarity()) end function ShipInfoKai:name() self._vars.name = Formatting:format_link(self._ship:base_link()) end function ShipInfoKai:localized_name() local localized_name = self._ship:localized_name() if localized_name then self._vars.localized_name = format{self._localized_name_template, localized_name = Formatting:format_stat(localized_name)} else self._vars.localized_name = "" end end function ShipInfoKai:japanese_name() self._vars.japanese_name = tostring(Formatting:japanese_text(Formatting:format_stat(self._ship:japanese_name()), Formatting:format_stat(self._ship:reading()))) end function ShipInfoKai:nick() local nick = self._ship:nick() if nick then local japanese_nick = self._ship:japanese_nick() local reading_nick = self._ship:reading_nick() if reading_nick then japanese_nick = tostring(Formatting:japanese_text{japanese_nick, reading_nick}) end self._vars.nick = format{self._nick_template, nick = nick, japanese_nick = japanese_nick} else self._vars.nick = "" end end function ShipInfoKai:id() local true_id = self._ship:true_id() if true_id then self._vars.id = Formatting:tooltip(Formatting:format_stat(self._ship:id()), Formatting:format_stat(true_id)) else self._vars.id = Formatting:format_stat(self._ship:id()) end end function ShipInfoKai:class() local class = self._ship:class() self._vars.class = Formatting:format_stat(class and class:name()) end function ShipInfoKai:type() local class = self._ship:class() local ship_type = Formatting:format_ship_type(self._ship:type()) if class and class:is_type() then ship_type = "(" .. ship_type .. ")" end self._vars.type = ship_type end function ShipInfoKai:image() self._vars.image = ShipCardKai:get{ship = self._ship} end function ShipInfoKai:hp() local hp = Formatting:format_stat(self._ship:hp()) --local hp_max = self._ship:hp_max() --if hp_max then -- self._vars.hp = Formatting:tooltip(hp, format{self._kekkon_max_template, value = Formatting:format_stat(hp_max)}) --else self._vars.hp = hp --end end function ShipInfoKai:firepower() self._vars.firepower = Formatting:format_stat_with_max(self._ship:firepower(), self._ship:firepower_max()) end function ShipInfoKai:armor() self._vars.armor = Formatting:format_stat_with_max(self._ship:armor(), self._ship:armor_max()) end function ShipInfoKai:torpedo() self._vars.torpedo = Formatting:format_stat_with_max(self._ship:torpedo(), self._ship:torpedo_max()) end function ShipInfoKai:evasion() local evasion, evasion_max local override = self._args.evasion local override_max = self._args.evasion_max local overridden = false if override and override ~= "auto" then evasion = override overridden = true else evasion = self._ship:evasion() end if override_max and override_max ~= "auto" then evasion_max = override_max overridden = true else evasion_max = self._ship:evasion_max() end local result = Formatting:format_stat_with_max(evasion, evasion_max) if not overridden and evasion and evasion_max then result = Formatting:tooltip(result, format{self._kekkon_max_template, value = Formatting:format_stat(self._ship:evasion_leveled(155))}) end if overridden then result = result .. self._overridden_category_template end self._vars.evasion = result end function ShipInfoKai:aa() self._vars.aa = Formatting:format_stat_with_max(self._ship:aa(), self._ship:aa_max()) end function ShipInfoKai:aircraft() self._vars.aircraft = Formatting:format_stat(self._ship:total_space()) end function ShipInfoKai:asw() local asw, asw_max local overridden = false local override = self._args.asw local override_max = self._args.asw_max if override and override ~= "auto" then asw = override overridden = true else asw = self._ship:asw() end if override_max and override_max ~= "auto" then asw_max = override_max overridden = true else asw_max = self._ship:asw_max() end local result = Formatting:format_stat_with_max(asw, asw_max) if not overridden and asw and asw_max then result = Formatting:tooltip(result, format{self._kekkon_max_template, value = Formatting:format_stat(self._ship:asw_leveled(155))}) end if overridden then result = result .. self._overridden_category_template end self._vars.asw = result end function ShipInfoKai:speed() self._vars.speed = Formatting:format_speed(self._ship:speed()) end function ShipInfoKai:los() local los, los_max local override = self._args.los local override_max = self._args.los_max local overridden = false if override and override ~= "auto" then los = override overridden = true else los = self._ship:los() end if override_max and override_max ~= "auto" then los_max = override_max overridden = true else los_max = self._ship:los_max() end local result = Formatting:format_stat_with_max(los, los_max) if not overridden and los and los_max then result = Formatting:tooltip(result, format{self._kekkon_max_template, value = Formatting:format_stat(self._ship:los_leveled(155))}) end if overridden then result = result .. self._overridden_category_template end self._vars.los = result end function ShipInfoKai:range() self._vars.range = Formatting:format_range(self._ship:range()) end function ShipInfoKai:luck() self._vars.luck = Formatting:format_stat_with_max(self._ship:luck(), self._ship:luck_max()) end function ShipInfoKai:build_remodel_header() self._vars.build_remodel_header = self._ship:remodel_from() and self._remodel_level or self._build_time end function ShipInfoKai:build_remodel_info() local remodel_from = self._ship:remodel_from() if remodel_from then self._vars.build_remodel_info = Formatting:format_remodel_level_and_item_cost(self._ship:remodel_level(), self._ship:remodel_blueprint(), self._ship:remodel_catapult()) self._vars.remodel_cost = format{self._remodel_cost_template, remodel_cost = Formatting:format_resources(self._ship:remodel_cost())} else local buildable = self._ship:buildable() local buildable_lsc = self._ship:buildable_lsc() if buildable or buildable_lsc then local buildable_methods = {} if buildable then table.insert(buildable_methods, Formatting:format_link(self._normal_construction_category, self._normal_construction)) end if buildable_lsc then table.insert(buildable_methods, Formatting:format_link(self._large_ship_construction_category, self._large_ship_construction)) end self._vars.build_remodel_info = Formatting:format_stat_with_max(Formatting:seconds_to_hms(self._ship:build_time() * 60), table.concat(buildable_methods, ", ")) else local build_time = self._ship:build_time() self._vars.build_remodel_info = build_time and Formatting:tooltip(self._unbuildable, Formatting:seconds_to_hms(build_time * 60)) or self._unbuildable end self._vars.remodel_cost = "" end if remodel_from ~= false and remodel_from self._ship:remodel_to() then self._vars.reversion_cost = format{self._reversion_cost_template, suffix = Formatting:format_stat(Ship(self._ship:remodel_to()):display_suffix()), level_items = Formatting:format_remodel_level_and_item_cost(self._ship:remodel_to_level(), self._ship:remodel_to_blueprint(), self._ship:remodel_to_catapult()), resources = Formatting:format_resources(self._ship:remodel_to_cost()) } else self._vars.reversion_cost = "" end end function ShipInfoKai:slots() self._vars.slots = Formatting:format_stat(self._ship:slots()) end function ShipInfoKai:slot_details() local slots, num_of_slots, num_of_enabled_slots, slots_to_show = {}, self._ship:slots_length(), self._ship:slots() if num_of_slots then slots_to_show = math.max(self._default_slot_num, num_of_slots) else slots_to_show = self._default_slot_num end for i = 1, slots_to_show do local disabled, equipment, size, estimation, icon, color, equipment_type = num_of_enabled_slots and i > num_of_enabled_slots if num_of_slots and i > num_of_slots then equipment, size, estimation, icon, color, equipment_type = "- Locked -", false, false, "", 0, false else equipment, size, estimation = self._ship:slot(i) if equipment then icon = equipment:icon() color = equipment:back() equipment_type = equipment:type() equipment = Formatting:format_link(equipment:link()) else icon = disabled and "" or false color = 0 equipment = equipment false and (disabled and "- Locked -" or "- Unequipped -") or Formatting:format_stat(equipment) equipment_type = false end if icon ~= "" then icon = Formatting:format_image{Formatting:format_equipment_icon(icon), caption = Formatting:format_equipment_type(equipment_type)} end end table.insert(slots, format{self._slot_template, icon = icon, equipment = equipment, slot_size = Formatting:format_slot_size(size, estimation), color = "whitesmoke", --Formatting:format_equipment_back(color), extra_style = "", --Formatting:extra_style_background_image(false, color >= 4) }) end self._vars.slot_details = table.concat(slots) end function ShipInfoKai:consumption() self._vars.fuel, self._vars.ammo = Formatting:format_stat(self._ship:fuel()), Formatting:format_stat(self._ship:ammo()) end function ShipInfoKai:modernization() self._vars.modernization = Formatting:format_modernization_bonuses(self._ship:modernization()) end function ShipInfoKai:scrap() self._vars.scrap = Formatting:format_resources(self._ship:scrap()) end function ShipInfoKai:gun_fit_properties() local ship_type = self._ship:type() if ship_type 8 or ship_type 9 or ship_type 10 then local rows = {} for _, fit_group in ipairs(require('Module:LargeCaliberMainGunFit').fit_groups) do table.insert(rows, format{self._gun_fit_group_template, fit_group = fit_group, fit = Formatting:format_fit_bonus(self._ship:gun_fit_properties(fit_group))}) end self._vars.gun_fit_properties = format{self._gun_fit_properties_template, gun_fit_groups = table.concat(rows)} else self._vars.gun_fit_properties = "" end end function ShipInfoKai:improvement() self._vars.improvement = format{self._improvement_template, category_tree = tostring(require('Module:CategoryTree'){category = format{self._improvement_category_template, ship_name = self._ship:name()}, depth = 1})} end function ShipInfoKai:create_item() if self._args.name then self._ship = Ship(self._args.name, self._args.model) else self._ship = Ship(self._args1) end end function ShipInfoKai:get_module() self._ship_data_module = Ship:get_module(self._args.name or self._args1) end function ShipInfoKai:create_infobox_prep() local icons = { hp = StatIcons.hp, firepower = StatIcons.firepower, armor = StatIcons.armor, torpedo = StatIcons.torpedo, evasion = StatIcons.evasion, aa = StatIcons.aa, aircraft = StatIcons.aircraft, asw = StatIcons.asw, speed = StatIcons.speed, los = StatIcons.los, range = StatIcons.range, luck = StatIcons.luck, fuel = ResourceIcons.fuel, ammo = ResourceIcons.ammo, } local labels = {} for k,v in pairs(icons) do iconsk = Formatting:format_image{v} labelsk = Formatting:format_stat_name(k) end self._vars = {icons = icons, labels = labels} local table_classes = {"typography-xl-optout", "infobox"} if self._args.classes then table.insert(table_classes, self._args.classes) end local collapsible = self._args.collapsible if collapsible then table.insert(table_classes, "mw-collapsible") table.insert(table_classes, "mw-collapsed") end self._vars.table_class = table.concat(table_classes, " ") self._vars.table_id = collapsible and collapsible ~= "true" and ("mw-customcollapsible-" .. collapsible) or "" self._vars.float = self._args.float or "none" end function ShipInfoKai:format_template() for _, field in ipairs(self._fields) do selffield(self) end return format(self._template, self._vars) end function ShipInfoKai:add_fields() return end function ShipInfoKai:create_infobox() self:add_fields() self:create_item() self:get_module() self:create_infobox_prep() return self:format_template() end return ShipInfoKai